Symbolizer.generator   B
last analyzed

Complexity

Conditions 6

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 7
dl 0
loc 10
ccs 4
cts 4
cp 1
crap 6
rs 8.6666
c 0
b 0
f 0
1
/**
2
 * @class Symbolizer
3
 * @name Symbolizer
4
 */
5 4
export class Symbolizer {
6 45
  symbols: string[] = []
7
8
  /**
9
   * Initialize a symbolizer.
10
   */
11
  constructor(symbols?: string) {
12 45
    if (symbols) this.symbols = symbols.split('')
13
  }
14
15
  /**
16
   * Symbol generator.
17
   */
18
  *generator(): Generator<string> {
19 30
    for (let i = 0; ; i++) {
20 75
      if (i < this.symbols.length) {
21 25
        yield this.symbols[i] ?? '?'
22
      } else {
23 50
        yield String.fromCharCode(945 + i - this.symbols.length)
24
      }
25
    }
26
  }
27
}
28
29
export default Symbolizer
30